<template>
  <a-card :bordered="false">


    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->


    <!-- 表单区域 -->
    <stmChannelProduct-modal ref="modalForm" @ok="modalFormOk"></stmChannelProduct-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import StmChannelProductModal from './modules/StmChannelProductModal'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import {deleteAction, getAction, postAction} from "@api/manage";


export default {
  name: "StmChannelProductFinanceApplyList",
  mixins: [JeecgListMixin],
  components: {
    StmChannelProductModal
  },
  data() {
    return {
      description: '渠道产品表管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '商品名称',
          align: "center",
          dataIndex: 'productName'
        },
        {
          title: '货号',
          align: "center",
          dataIndex: 'productSn'
        },
        {
          title: '物料编码',
          align: "center",
          dataIndex: 'skuCode'
        },
        {
          title: '价格',
          align: "center",
          dataIndex: 'price'
        },

        {
          title: '生效日期',
          align: "center",
          dataIndex: 'beginTime'
        }

      ],
      url: {
        list: "/stm/stmChannelProductApplyItem/list",
        deleteBatch: "/stm/stmChannelProductApplyItem/deleteBatch",
        approve: "/stm/stmChannelProductApplyItem/approve",
      },
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    loadData(arg) {
      if (arg === 1) {
        this.ipagination.current = 1
      }
      if (this.queryParam.mainId == null) {
        return;
      }
      var params = this.getQueryParams()
      getAction(this.url.list, {
        applyId: params.mainId
        , pageNo: this.ipagination.current, pageSize: this.ipagination.pageSize
      }).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records
          this.ipagination.total = res.result.total
        } else {
          this.dataSource = null
        }
      })
    },
    getMain(mainId) {
      this.queryParam.mainId = mainId
      this.loadData(1)
    },
    handleApprove() {
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！');
        return;
      } else {
        var ids = "";
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ",";
        }
        var that = this;
        that.loading = true;
        getAction(that.url.approve, {ids: ids, status: 3}).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
        }).finally(() => {
          that.loading = false;
        });

      }
    }
  }
}
</script>
<style scoped>
.ant-card {
  margin-left: -24px;
  margin-right: -24px;
}
</style>